﻿using System;
using System.Collections.Generic;
using System.Text;
using MyDMS.BusinessLayer.DataLayer;

namespace MyDMS.BusinessLayer
{
    public class SqlFactory
    {
        #region InnerClass
        public enum DataObjectType
        {
            DataSet = 1,
            DataTable = 2,
            DataReader = 3
        }
        #endregion

        #region data Members

        QuerySql _dataObject = null;

        #endregion

        #region Constructor

        public SqlFactory()
        {
            _dataObject = new QuerySql();
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Executes the given stored procedure with given parameters
        /// </summary>
        /// <param name="StoredProcedure">SP</param>
        /// <param name="sqlParameters">Parameters</param>
        /// <returns>true if successful</returns>
        public bool ExecuteSP(string StoredProcedure, params object[] sqlParameters)
        {
            if (StoredProcedure == null && StoredProcedure == string.Empty)
            {
                throw new InvalidBusinessObjectException("Invalid SP");
            }

            return _dataObject.ExecuteSP(StoredProcedure, sqlParameters);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sqlQuery"></param>
        /// <param name="dataObjectType"></param>
        /// <returns></returns>
        public bool ExecuteNonQuery(string sqlQuery)
        {
            if (sqlQuery == null && sqlQuery == string.Empty)
            {
                throw new InvalidBusinessObjectException("Invalid Query string");
            }
            return _dataObject.ExecuteNonQuery(sqlQuery);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sqlQuery"></param>
        /// <param name="dataObjectType"></param>
        /// <returns></returns>
        public bool ExecuteQuery(string sqlQuery, out object dataObject, DataObjectType dataObjectType)
        {
            if (sqlQuery == null && sqlQuery == string.Empty)
            {
                throw new InvalidBusinessObjectException("Invalid Query string");
            }

            return _dataObject.ExecuteQuery(sqlQuery, out dataObject, (int)dataObjectType);
        }

        #endregion
    }


}
